package com.sigmazero13.gameutils.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class GamePlayInfo implements Comparable<GamePlayInfo> {
	
	private GameInfo game;
	private Long playId;
	private Date gameDate;
	private String location;
	private String scenario;
	private Integer gameLength;
	private Integer numPlayers = 0;
	private List<GamePlayerInfo> players = new ArrayList<GamePlayerInfo>();
	
	public GameInfo getGame() {
		return game;
	}
	public void setGame(GameInfo game) {
		this.game = game;
	}
	public Long getPlayId() {
		return playId;
	}
	public void setPlayId(Long playId) {
		this.playId = playId;
	}
	public Date getGameDate() {
		return gameDate;
	}
	public void setGameDate(Date gameDate) {
		this.gameDate = gameDate;
	}
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	public String getScenario() {
		return scenario;
	}
	public void setScenario(String scenario) {
		this.scenario = scenario;
	}
	public Integer getGameLength() {
		return gameLength;
	}
	public void setGameLength(Integer gameLength) {
		this.gameLength = gameLength;
	}
	public List<GamePlayerInfo> getPlayers() {
		return players;
	}
	public void addPlayer(GamePlayerInfo player) {
		players.add(player);
		numPlayers = players.size();
	}
	public Integer getNumPlayers() {
		if ((numPlayers == null || numPlayers == 0) && players != null) {
			return players.size();
		}
		return numPlayers;
	}
	public void setNumPlayers(Integer numPlayers) {
		this.numPlayers = numPlayers;
	}
	
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		
		sb.append("PLAY INFO {\n");
		sb.append("Game: " + getGame() + "\n");
		sb.append("Date: " + getGameDate() + "\n");
		sb.append("Location: " + getLocation() + "\n");
		sb.append("Scenario: " + getScenario() + "\n");
		sb.append("Length: " + getGameLength() + " minutes\n");
		sb.append("Players: \n");
		for (GamePlayerInfo player : getPlayers()) {
			sb.append(player + "\n");
		}
		sb.append("}");
		
		return sb.toString();
	}
	
	@Override
	public int compareTo(GamePlayInfo another) {
		Date otherDate = another.getGameDate();
		
		if (this.gameDate.before(otherDate)) 
			return -1;
		else if (this.gameDate.after(otherDate))
			return 1;
		else 
			return this.playId < another.getPlayId()?-1:1;
	}
}
